package com.wust.tieshi;

import java.io.IOException;

import com.wust.R;
import com.wust.task.Task;
import com.wust.task.TaskDao;

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.content.Context;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

/**
 * @author 郭宏志
 * 提醒用户
 */
public class AlarmActivity extends Activity {
	public static final int ID = 1;
	private TextView viewtext;
	private Button okbtn;
	private TaskDao taskDao;
	private String msg ;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.alarm);
		viewtext=(TextView)findViewById(R.id.msgTextView01);
		okbtn=(Button)findViewById(R.id.cancelButton01);
		taskDao=new TaskDao(this);
		// 获得Button、TextView实例
		 msg = getIntent().getStringExtra("msg1");
		 System.out.println("msg"+msg);
		Task task=taskDao.getTask(msg);
		viewtext.setText(task.getCreated());
		System.out.println("start alrm");
		// 获得NotificationManager实例
		String service = Context.NOTIFICATION_SERVICE;
		final NotificationManager nm = (NotificationManager)getSystemService(service);
		// 实例化Notification
		Notification n = new Notification();
		// 设置显示提示信息，该信息也会在状态栏显示
		n.defaults=Notification.DEFAULT_SOUND;
		
		nm.notify(ID, n);
		// 取消通知
		okbtn.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				nm.cancel(ID);
				taskDao.deleteTask(msg);
				finish();
			}
		});
	}
	
}
